//
//  TTAnnotationManager.swift
//  TTBLL
//
//  Created by Toj on 3/15/21.
//

import Foundation

public enum TTAnnotationRole: Int {
    case admin
    case attendee
    case viewer
}

open class TTAnnotationManager: NSObject {
    
    public static let shared = TTAnnotationManager()
    private var annotation: TTAnnotationModel?
    
    private var server = TTAnnotationServer.shared
    
    public func setupParameters(annotation: TTAnnotationModel) {
        let ann = TTAnnotationModel()
        ann.appId = "4fd59df8d9164fd79bb746303fa9e118" // 替换为你的应用ID
        ann.rtcServer = "api.pano.video" // PANO服务器地址
        
        ann.token = "01000003SmlPbzBzN1X/to2tuzX3H2CGa6Jkf+006lJHUKeO9un6MFcZWDTBbOPMgg8Gx8L6QBJpzK+DleFArNADR6p4jRB7u0RZzS4eGf97hG14sPgdmIJNGG8kUjh8h0SFYAPtlOODrD4tI54qDARzFtcJiGm+KMvr/LZkOz4K6PwN2NPyaMG18xcbT5UQKdqEwx7fMqPBZ6O3N5t2biG3xsmZ3Y7tm5VA4nOTjH0WWyCOX+x16u7KtU2dW8Y73iioZUpRrR4CCnbRzfR58BA0SNh5Da3/bmmDbU6b"
        ann.channelId = "vipcode"
        ann.userid = UInt64(arc4random_uniform(100)) + 100
      
        self.annotation = ann
        
        server.setupServer(annotation: ann)
    }
    
    public func joinChannel(view: TTView) {
        server.didJoined = { [weak self ] in
            self?.startAnnotation(view: view)
        }
        server.joinChannel()
    }
    
    public func startAnnotation(view: TTView) {
        server.startAnnotation(view: view)
    }
    
    public func stopAnnotation() {
        server.stopAnnotation()
    }
    
    public func setRoleType(role: TTAnnotationRole) {
        server.setRoleType(role: role.rawValue)
    }
    
    deinit {
        annotation = nil
    }
}
